package com.dyylearn.servlet.homework;

import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet(urlPatterns = {"/pig1", "/pig2"}, loadOnStartup = 1)
public class PigServlet extends HttpServlet {
    private int getCount = 0;
    private int postCount = 0;

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //如何输出浏览器/客户端的ip
        //00P程序员，一定要考虑使用对象方法
        System.out.println("访问的浏览器的ip=" + req.getRemoteAddr());
        System.out.println("PigServlet Get访问次数count=" + (++getCount));
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        System.out.println("访问的浏览器的ip=" + req.getRemoteAddr());
        System.out.println("PigServlet Post访问次数count=" + (++postCount));
    }

    @Override
    public void service(ServletRequest req, ServletResponse res) throws ServletException, IOException {
        super.service(req, res);
    }
}
